#ifndef HEARTBEAT_LISTENER_H
#define HEARTBEAT_LISTENER_H
#include "rms_pkg/msg/heartbeat.hpp"
#include <QObject>
#include <QMutex>
#include <QVariantMap> 
#include <rclcpp/rclcpp.hpp>
#include "heartbeat_model.h"

class HeartbeatListener : public QObject, public rclcpp::Node {
    Q_OBJECT
public:
    explicit HeartbeatListener(HeartbeatModel* model);
    ~HeartbeatListener() = default;

signals:
    void heartbeatSignal(const QVariantMap &robotData);
    void timeoutCheckRequestedSignal(int timeoutSeconds);

private:
    // 明确指定回调函数类型
    void heartbeat_callback(const rms_pkg::msg::Heartbeat::SharedPtr msg);
    void check_timeout();

    HeartbeatModel* model_;
    rclcpp::Subscription<rms_pkg::msg::Heartbeat>::SharedPtr subscription_;
    rclcpp::TimerBase::SharedPtr timer_;
    int timeout_ = 5;
    QMutex data_mutex_;
};

#endif // HEARTBEAT_LISTENER_H